<template>
  <el-card>
    <div class="header-bar">
      <span class="title">统计报表分析</span>
      <el-date-picker
        v-model="dateRange"
        type="daterange"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        size="small"
        style="width:240px;margin-right:10px;"
        value-format="YYYY-MM-DD"
        clearable
      />
      <el-select
        v-model="warehouse"
        placeholder="库房"
        size="small"
        style="width:120px;margin-right:10px;"
        clearable
      >
        <el-option label="全部" value="" />
        <el-option label="总库房" value="总库房" />
        <el-option label="住院部库房" value="住院部库房" />
        <el-option label="门诊库房" value="门诊库房" />
      </el-select>
      <el-button type="primary" size="small" @click="onExport">导出报表</el-button>
    </div>
    <el-row :gutter="16" style="margin-top:8px;">
      <el-col :span="12">
        <el-card>
          <div class="stat-title">设备状态分布</div>
          <v-chart :option="deviceStatusOption" style="height: 280px;" />
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card>
          <div class="stat-title">物资库存趋势</div>
          <v-chart :option="stockTrendOption" style="height: 280px;" />
        </el-card>
      </el-col>
    </el-row>
    <el-row :gutter="16" style="margin-top:18px;">
      <el-col :span="12">
        <el-card>
          <div class="stat-title">入库/出库统计</div>
          <v-chart :option="inOutOption" style="height: 280px;" />
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card>
          <div class="stat-title">告警数量趋势</div>
          <v-chart :option="alarmTrendOption" style="height: 280px;" />
        </el-card>
      </el-col>
    </el-row>
  </el-card>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import VChart from 'vue-echarts'

// 筛选条件
const dateRange = ref([])
const warehouse = ref('')

// 模拟数据-设备状态分布
const deviceStatusOption = {
  tooltip: { trigger: 'item' },
  legend: { top: '5%', left: 'center' },
  series: [
    {
      name: '状态',
      type: 'pie',
      radius: ['40%', '70%'],
      label: { show: false },
      emphasis: { label: { show: true, fontSize: 16, fontWeight: 'bold' } },
      data: [
        { value: 48, name: '在用' },
        { value: 6, name: '停用' },
        { value: 7, name: '维修中' }
      ]
    }
  ]
}

// 模拟数据-物资库存趋势
const stockTrendOption = {
  tooltip: { trigger: 'axis' },
  legend: { data: ['总库房', '住院部库房', '门诊库房'] },
  xAxis: { type: 'category', data: ['6-01', '6-05', '6-10', '6-15', '6-20'] },
  yAxis: { type: 'value' },
  series: [
    { name: '总库房', type: 'line', data: [820, 860, 810, 800, 830] },
    { name: '住院部库房', type: 'line', data: [410, 420, 395, 410, 408] },
    { name: '门诊库房', type: 'line', data: [305, 316, 312, 320, 315] }
  ]
}

// 模拟数据-入库/出库统计
const inOutOption = {
  tooltip: { trigger: 'axis' },
  legend: { data: ['入库', '出库'] },
  xAxis: { type: 'category', data: ['6-01', '6-05', '6-10', '6-15', '6-20'] },
  yAxis: { type: 'value' },
  series: [
    { name: '入库', type: 'bar', data: [120, 132, 101, 134, 90] },
    { name: '出库', type: 'bar', data: [60, 72, 80, 90, 70] }
  ]
}

// 模拟数据-告警数量趋势
const alarmTrendOption = {
  tooltip: { trigger: 'axis' },
  xAxis: { type: 'category', data: ['6-01', '6-05', '6-10', '6-15', '6-20'] },
  yAxis: { type: 'value' },
  series: [
    { name: '告警数', type: 'line', smooth: true, data: [4, 9, 8, 7, 3] }
  ]
}

function onExport() {
  ElMessage.info('演示：这里可对接报表导出功能（Excel/图片）')
}
</script>

<style scoped>
.header-bar {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}
.title {
  font-size: 20px;
  font-weight: bold;
  margin-right: 20px;
}
.stat-title {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 6px;
}
</style>
